home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ZED3DSRC.ZIP / OBJECTS.H < prev    next >
C/C++ Source or Header  |  1995-06-19  |  4KB  |  132 lines

  1. #ifndef __OBJECTS_H
  2. #define __OBJECTS_H
  3.  
  4. #include <xforms.h>
  5.  
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9.  
  10. /* #define __vertexnormals__ */
  11. /* that last define enables vertex normals. these are used for shading
  12.    objects using Gouraud or Phong shading, for example. Put it in comments
  13.    if you want it out, put the comments in if you want it in */
  14.  
  15.  
  16. struct point_struct
  17.     {
  18.     vector location;
  19. #ifdef __vertexnormals__
  20.     vector normal;
  21. #endif
  22.     long clipping;
  23.     };
  24.  
  25.  
  26. typedef struct point_struct point;
  27.  
  28.  
  29. struct pointcollection_struct
  30.     {
  31.     point *vertex; /* array of vertices */
  32.     long numpoints;
  33.     };
  34.  
  35. typedef struct pointcollection_struct pointcollection;
  36.  
  37. struct face_struct
  38.     {
  39.     long *index; /* index to array of points, whatever */
  40.     long numpoints;
  41.     vector normal;
  42.     REAL D; /* D component of plane eq. Ax+By+Cz=D */
  43.     };
  44.  
  45. typedef struct face_struct face;
  46.  
  47. struct facecollection_struct
  48.     {
  49.     face *face;
  50.     long numfaces;
  51.     };
  52.  
  53. typedef struct facecollection_struct facecollection;
  54.  
  55.  
  56. struct object_struct
  57.     {
  58.     pointcollection *pts_data;
  59.     facecollection *face_data;
  60.     long usecount; /* number of times this object has been cloned, see below */
  61.     };
  62.  
  63. typedef struct object_struct object;
  64.  
  65. pointcollection *alloc_pointcollection(int numpoints);
  66.     /* allocates a brand-new pointcollection with all associated data
  67.        allocated but uninitialized */
  68. void free_pointcollection(pointcollection *p);
  69.     /* frees an allocated pointcollection */
  70.  
  71. facecollection *alloc_facecollection(int numfaces);
  72.     /* allocates a facecollection. note: does not allocate any
  73.        f->face[i].index, instead initializes them to 0 */
  74.  
  75. void free_facecollection(facecollection *f);
  76.     /* frees an allocated facecollection. note: also frees all
  77.        f->face[i].index */
  78.  
  79. object *alloc_object(long numpoints, long numfaces);
  80. void free_object(object *o);
  81.     /* IBID */
  82. object *clone_object(object *o);
  83.     /* creates and returns a clone of object o. all data structures
  84.        are shared. the usecount is incremented. free_object is made
  85.        so that it first decrements usecount and only frees all memory
  86.        if usecount is zero */
  87.  
  88.  
  89. int init_facepts(face *f, long numpoints);
  90.     /* allocates memory for index and sets numpoints. return 0 on success,
  91.        nonzero on failure */
  92.  
  93.  
  94. REAL compute_2area(face *f, point *p, int axis1, int axis2);
  95.     /* computes the signed area of polygon projected on axis1 X axis2
  96.        plane. This is used to compute plane normal (it actually returns
  97.        twice the signed area) */
  98.  
  99. void init_normals(object *o);
  100.     /* computes all plane normals then calls fix_D. also computes the
  101.        o->pts_data->vertex[...].clipping counters */
  102.  
  103. void normalize_object(object *o);
  104.     /* makes all normals of unit length, then calls fix_D */
  105.  
  106. void fix_D(object *o);
  107.     /* fixes all values for D if somehow they're messed */
  108.  
  109. int make_tetrahedron(object *o);
  110.     /* given an object of 4 faces, 4 vertices, with initialized vertices
  111.        (the rest left uninitialized), this routine will make a
  112.        tetrahedron out of it. It will return 0 if everything is fine,
  113.        nonzero if the tetrahedron is degenerate (e.g. too slim). In this
  114.        latter case, it can still be used, but it might not look like a
  115.        tetrahedron at all. Example call to make_tetrahedron (RAND is
  116.        a function returning a random REAL value):
  117.  
  118.        object *o;
  119.        long a,b;
  120.        o=alloc_object(4,4);
  121.        for(a=0;a<4;a++)
  122.            for(b=0;b<3;b++)
  123.                o->pts_data->vertex[a].location[b]=RAND();
  124.        make_tetrahedron(o);
  125.     */
  126.  
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130.  
  131. #endif
  132.